package iziswing.composant;

import java.awt.Container;
import java.awt.Point;

import javax.swing.BorderFactory;
import javax.swing.JComponent;

import metier.ContexteComposant;

import org.apache.log4j.Logger;

import exception.ComposantException;

@SuppressWarnings("serial")
public class JPanel extends javax.swing.JPanel {

	private static Logger mLogger = Logger.getLogger(JTextArea.class.getName());

	private Container mFenetre;
	private ContexteComposant mContexte;
	public JPanel(Container aFenetre, ContexteComposant aContexte) {
		super();
		mFenetre = aFenetre;
		mContexte = aContexte;
		Point lPoint = ComposantTools.getSize(mContexte);
		setBounds(mContexte.getX(),mContexte.getY(),lPoint.y,lPoint.x);
		setBorder(BorderFactory.createTitledBorder(aContexte.getTitre())); 
		mFenetre.add(this);
	}

	@SuppressWarnings("unchecked")
	public static Object newInstance(Container aFenetre, ContexteComposant aContexte,
			Object aComposantOut) throws ComposantException {
		try {
			Class<JComponent> lComposant = (Class<JComponent>) Class
					.forName(aContexte.getModeleClasse().getClasse());
			if (lComposant.equals(JPanel.class)) {
				aComposantOut = new JPanel(aFenetre,aContexte);
			}
		} catch (ClassNotFoundException e) {
			mLogger.debug(e);
		}
		return aComposantOut;
	}
}
